package cn.com.greatwall.system.config.thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import cn.com.greatwall.common.utils.SpringContextHolder;

/**
 * @Author herw
 * @Time 2020-11-04 15:04:12
 * @Version 1.0
 * @Description: 用于获取自定义线程池
 */
public class ThreadPoolExecutorUtil {
    public static ThreadPoolExecutor getPool() {
        AsyncTaskProperties properties = SpringContextHolder.getBean(AsyncTaskProperties.class);
        return new ThreadPoolExecutor(properties.getCorePoolSize(), properties.getMaxPoolSize(),
                properties.getKeepAliveSeconds(), TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(properties.getQueueCapacity()), new TheadFactoryName());
    }
}
